<?php
/**
 * 简易版品牌咨询管理
 * @author Ice <iceinto@mallog.com.cn>
 */
class BrandNewsModel extends BaseModel
{
	//自动验证
	protected $_validate = array(
			array('title', 'require', '标题必须！', self::MUST_VALIDATE),
			array('mid', 'require', '商场必须！', self::MUST_VALIDATE),
			array('fid', 'require', '楼层必须！', self::MUST_VALIDATE),
			array('bid', 'require', '品牌必须！', self::MUST_VALIDATE),
			array('editor', 'require', '负责人必须！', self::MUST_VALIDATE),
			array('keyword', 'require', '搜索关键字必须！', self::MUST_VALIDATE),
			array('model', 'require', '文章模式必须！', self::MUST_VALIDATE));
	//自动完成
	protected $_auto = array(
			array('create_time', 'time', self::MODEL_INSERT, 'function'),
			array('last_update', 'time', self::MODEL_BOTH, 'function'));
	public function getIndexData ($mId = 0, $fId = 0, $bId = 0, $model = 0)
	{
		$map = array();
		if ($mId) {
			$map['mid'] = $mId;
		}
		if ($fId) {
			$map['fid'] = $fId;
		}
		if ($bId) {
			$map['bid'] = $bId;
		}
		if ($model) {
			$map['model'] = $model;
		}
		$allCount = $this->where($map)->count();
		$Page = $this->getPage($allCount);
		$data = $this->where($map)
		->order('id DESC')
		->limit($Page->firstRow . ',' . $Page->listRows)
		->select();
		return array('data' => $data, 'page' => $Page->show());
	}
	/**
	 * 资讯高级管理获取
	 * @author Ice <iceinto@mallog.com.cn>
	 */
	public function getManagedNews ($map = array())
	{
		$allCount = $this->where($map)->count();
		$Page = $this->getPage($allCount);
		$data = $this->where($map)
		->field('m_brand_news.id,m_brand_news.title,m_brand_news.mid,m_brand_news.fid,m_brand_news.bid,m_market.name as market_name,m_floor.sain,m_floor.name as floor_name,m_brand.name as brand_name')
		->join('LEFT JOIN m_market ON m_brand_news.mid = m_market.id')
		->join('LEFT JOIN m_floor ON m_brand_news.fid = m_floor.id')
		->join('LEFT JOIN m_brand ON m_brand_news.bid = m_brand.id')
		->limit($Page->firstRow . ',' . $Page->listRows)
		->order('m_brand_news.id DESC')
		->select();
		return array('data' => $data, 'page' => $Page->show());
	}
}
?>